package com.huawei.utils;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class SystemUtils {
    /** SystemUtils
     *  主要负责随机算法以及胜负判断
     */
    public static List<Integer> resultNumbers=new ArrayList<>();
    public static String onRandomResult()
    {
        Random random=new Random();
        int numx=random.nextInt(3);
        //防止重复多次进行
        String plans=setplans(numx);
        return plans;
    }


    /**设置返回字符串
     *
     * @param num
     * @return
     */
    public static String setplans(int num){


        switch (num){
            case 0:
                return "石头";
            case 1:
                return "布";
            case 2:
                return "剪刀";
        }
        return null;
    }

    /** 游戏计算结果
     *
     * @param personPlans
     * @param systemPlans
     */
    public static void endResult(String personPlans,String systemPlans)
    {
        int wins=0;
        switch (personPlans){
            case "石头":
                wins=isWin(systemPlans);
                if (wins==1) {
                    System.out.println("你输了！");
                }else if(wins==2){
                    System.out.println("你赢了！");
                }else if(wins==0) {
                    System.out.println("平局！");
                }
                break;
            case "剪刀":
                wins=isWin(systemPlans);
                if (wins==1) {
                    System.out.println("你赢了！");
                }else if(wins==2){
                    System.out.println("平局！");
                }else if(wins==0) {
                    System.out.println("你输了！");
                }
                break;
            case "布":
                wins=isWin(systemPlans);
                if (wins==1) {
                    System.out.println("平局！");
                }else if(wins==2){
                    System.out.println("你输了！");
                }else if(wins==0) {
                    System.out.println("你赢了！");
                }
                break;
        }

    }

    /** 根据字符串返回数字进行比较
     *
     * @param systemPlans
     * @return
     */

    public static int isWin(String systemPlans){
        //0-石头
        if (systemPlans.equalsIgnoreCase("石头")) {
            return 1;
        }
        else if (systemPlans.equalsIgnoreCase("剪刀"))
        {
            return 2;
        }
        else if (systemPlans.equalsIgnoreCase("布")){
            return 0;
        }
        return -1;
    }

    public static boolean isExit(String exitStr)
    {
        if (exitStr.equalsIgnoreCase("q")) {
            return true;
        }
        return false;
    }
}
